<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>公众号管理</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-
scale=1, user-scalable=no">

    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../css/y_index.css" />
    <style>
    .rbox {
        width: 1rem;
        height: .22rem;
        border: 1px solid #333;
    }

    .rbox1 {
        width: 1rem;
        height: .22rem;
    }

    .main_btn {
        margin-bottom: .7rem;
    }

    .scroll_list {
        white-space: nowrap;
        overflow-x: scroll;
    }
    .colc {
	    width: 50%;
	    text-align: center;
	}
    </style>
</head>

<body>
    <div class="bigBox">
        <div class="top flex_sa bw p20">
            <li class="colc active">已上架</li>
            <li class="colc">已下架</li>
        </div>
        <div class="container">
            <div class="bw mt20 wx_list">
                <!--<div class="list flex_sb p20 bdb">
                    <div class="flex_a">
                        <img src="../img/y_8.png" style="width: 1.5rem;height: 1.5rem" />
                        <ul class="flex flex_column ml20">
                            <li>LION 公众号</li>
                            <li class="c2 mt20">已上架</li>
                        </ul>
                    </div>
                    <span class="p20 border-r4 rbox flex_aj">下架</span>
                </div>-->
                <!--<div class="list flex_sb p20 bdb touchMe">
                    <div class="flex_a">
                        <img src="../img/y_8.png" style="width: 1.5rem;height: 1.5rem" />
                        <ul class="flex flex_column ml20">
                            <li>LION 公众号</li>
                            <li class="c2 mt20">已下架</li>
                        </ul>
                    </div>
                    <div class="flex_a">
                        <span class="p20 border-r4 rbox flex_aj">编辑</span>
                        <span class="p20 border-r4 colw rbox1 flex_aj ml20 b_diy1">上架</span>
                    </div>
                </div>-->
                <!--<div class="weui-cell_swiped" style="position: relative;">-->
			    	<!--<div class="list flex_sb p20 bdb weui-cell__bd">-->
	                    <!--<div class="flex_a">-->
	                        <!--<img src="../img/y_8.png" style="width: 1.5rem;height: 1.5rem" />-->
	                        <!--<ul class="flex flex_column ml20">-->
	                            <!--<li>LION 公众号</li>-->
	                            <!--<li class="c2 mt20">已上架</li>-->
	                        <!--</ul>-->
	                    <!--</div>-->
	                    <!--<span class="p20 border-r4 rbox flex_aj">下架</span>-->
	                <!--</div>-->
			    	<!--<div class="weui-cell__ft">-->
			        <!--<a class="weui-swiped-btn weui-swiped-btn_warn delete-swipeout flex_a del" href="javascript:">删除</a>-->
			      <!--</div>-->
			    <!--</div>-->
			    <!--<div class="weui-cell_swiped" style="position: relative;">-->
			    	<!--<div class="list flex_sb p20 bdb touchMe weui-cell__bd">-->
	                    <!--<div class="flex_a">-->
	                        <!--<img src="../img/y_8.png" style="width: 1.5rem;height: 1.5rem" />-->
	                        <!--<ul class="flex flex_column ml20">-->
	                            <!--<li>LION 公众号</li>-->
	                            <!--<li class="c2 mt20">已下架</li>-->
	                        <!--</ul>-->
	                    <!--</div>-->
	                    <!--<div class="flex_a">-->
	                        <!--<span class="p20 border-r4 rbox flex_aj">编辑</span>-->
	                        <!--<span class="p20 border-r4 colw rbox1 flex_aj ml20 b_diy1">上架</span>-->
	                    <!--</div>-->
	                <!--</div>-->
			    	<!--<div class="weui-cell__ft">-->
			        <!--<a class="weui-swiped-btn weui-swiped-btn_warn delete-swipeout flex_a" href="javascript:">删除</a>-->
			      <!--</div>-->
			    <!--</div>-->
            </div>
             
        </div>
        <div class="main_btn">添加公众号</div>
    </div>
</body>

</html>
<script src="../js/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/dlc.js" type="text/javascript" charset="utf-8"></script>
<!--<script src="../js/swiper.min.js" type="text/javascript" charset="utf-8"></script>-->
<script src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.0/alipayjsapi.inc.min.js"></script>
<!--<script src="../js/swipeout.js" type="text/javascript" charset="utf-8"></script>-->
<!--公司的常用函数封装-->
<script type="text/javascript">
$('.top').on('click', 'li', function() {
    $(this).addClass('active').siblings().removeClass('active');
    wx_list($(this).index()+1,1)
})
// 长按删除
//$(".touchMe").on({
//  touchstart: function(e) {
//      var index = $(this).index();
//      console.log(index);
//
//      // 将当前元素的索引作为参数进行传递
//      timeOutEvent = setTimeout("longPress(" + index + ")", 500);
//      e.preventDefault();
//  },
//  touchmove: function() {
//      clearTimeout(timeOutEvent);
//      timeOutEvent = 0;
//  },
//  touchend: function() {
//      clearTimeout(timeOutEvent);
//      if (timeOutEvent != 0) {
//          alert('你这是点击，不是长按');
//      }
//      return false;
//  }
//})
//
//function longPress(t) {
//  timeOutEvent = 0;
//  if (confirm('您确定要删除？' + t)) {
//      // 用传递过来的参数定位当前元素
//      $('.touchMe').eq(0).remove();
//      console.log('已删除');
//  }
//}
$('.main_btn').on('click', function() {
    location.href = 'ser_addWechat.html?deviceNo='+getUrlParam('deviceNo')
});

//滑动删除
// $('.wx_list').on('click','.weui-cell__ft .del',function () {
// 	console.log($(this).index());
// 	console.log(111)
//   	$(this).parents('.weui-cell_swiped').remove()
//   });
$('.wx_list').on('click','.Del',function(){
    console.log('del');
    var _this = this;
    dlctipbox.confirm('是否删除？',function(index){
        if(index == 1){
            $.ajax({
                type:"post",
                url:dlcUrl()+"/api/officialAccounts/delete",
                dataType: 'json',
                data:{id:$(_this).data('ids')},
                success: function(res) {
                    console.log(res);
                    if(res.code==1){
                        dlctipbox.show(res.msg);
                        wx_list(1,1)
                    }else{
                        dlctipbox.show(res.msg)
                    }
                }
            });
        }
    });

});



wx_list(1,1)
function wx_list(id,page){
	$.ajax({
		type:"post",
		url:dlcUrl()+"/api/officialAccounts/list",
		dataType: 'json',
		data:{deviceNo:getUrlParam('deviceNo'),status:id,page:page,limit:10},
		success: function(res) {
			console.log(res);
			var html='';
			$('.wx_list').children().remove();
			res.data.list.forEach(function(item,index){
                html += '<div class="weui-cell_swiped" style="position: relative;">\n' +
                    '<div class="list flex_sb p20 bdb touchMe weui-cell__bd">\n' +
                    '<div class="flex_a">\n' +
                    '<img src="'+dlcUrl()+item.imgUrl+'" style="width: 1.5rem;height: 1.5rem" />\n' +
                    '<ul class="flex flex_column ml20">\n' +
                    '<li>'+item.name+'</li>\n' +
                    '<li class="c2 mt20">'+(item.status==1?"已上架":"已下架")+'</li>\n' +
                    '</ul>\n' +
                    '</div>\n' +
					(item.status==1?'<span class="p20 border-r4 rbox flex_aj down" data-id="'+item.id+'">下架</span>':'<div class="flex_a"><span class="p20 border-r4 rbox flex_aj bian" data-i="'+item.id+'" data-Did="'+item.deviceId+'" data-No="'+item.deviceNo+'" data-ai="'+item.agentId+'">编辑</span><span class="p20 border-r4 colw rbox1 flex_aj ml20 b_diy1" data-id="'+item.id+'">上架</span></div>')+
                    '<img src="../img/del.png" style="width:0.3rem;height:0.31rem;" class="Del" data-ids="'+item.id+'">'+
                    '</div>'+
                    '</div>'
			})
			$('.wx_list').append(html)
		}
	});
}

//上架
	$('.wx_list').on('click','.b_diy1',function(){
        var that = this;
        dlctipbox.confirm('是否上架？',function(index){
            if(index == 1){
             	go($(that).data('id'),1)
            }
        });
	});

    //下架
$('.wx_list').on('click','.down',function(){
    var that = this;
    dlctipbox.confirm('是否下架？',function(index){
        if(index == 1){
            go($(that).data('id'),2)
        }
    });
});

    //编辑

$('.wx_list').on('click','.bian',function(){
    var that = this;
    dlc_request('/api/officialAccounts/isEdit', { agentId: $(this).data('ai')}, function(res) {
        console.log(res);
        if(res.code==1){
            location.href='ser_editWechat.html?id='+$(that).data('i')+'&deviceId='+$(that).data('did')+'&deviceNo='+$(that).data('no');
        }else{
            dlctipbox.alert(res.msg);
        }
    });
});

	function go(idx,type){
        $.ajax({
            type:"post",
            url:dlcUrl()+"/api/officialAccounts/updateStatus",
            dataType: 'json',
            data:{id:idx,status:type},
            success: function(res) {
                console.log(res);
				if(res.code==1){
				    dlctipbox.show(res.msg);
                    wx_list(1,1)
				}else{
				    dlctipbox.show(res.msg)
				}
            }
        });
	}
</script>